package org.rc.component;


import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.rc.dto.KeyWordGroup;
import org.rc.util.HttpClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class DtComponent {

    @Value("${alarm.keyWord.url}")
    private String alarmKeyWordUrl;


    public List<KeyWordGroup> getKeyWordDic (){
        //获取预警关键词
        Map<String, String> keyWordPage = new HashMap<>();
        keyWordPage.put("roomTypeCode","D006001");
        keyWordPage.put("pageNo","1");
        keyWordPage.put("pageNum","100");
        String result = HttpClient.get(alarmKeyWordUrl,keyWordPage);
        if(StringUtils.isNotEmpty(result)){
            JSONObject jsonObject = JSONObject.parseObject(result);
            Object rows = JSONObject.parseObject(JSONObject.toJSONString(jsonObject.get("data"))).get("rows");
            return JSONObject.parseArray(JSONObject.toJSONString(rows),KeyWordGroup.class);
        }
        return null;
    }
}
